package com.example.xmlfactory;

import com.example.xmlfactory.parse.Parser;
import com.example.xmlfactory.parse.Serializer;
import com.example.xmlfactory.parse.dom.DomParser;
import com.example.xmlfactory.parse.dom.DomSerializer;
import com.example.xmlfactory.parse.pull.PullParser;
import com.example.xmlfactory.parse.pull.PullSerializer;
import com.example.xmlfactory.parse.sax.SaxParser;
import com.example.xmlfactory.parse.sax.SaxSerializer;

/**
 * Created by huangbei on 2017/9/11.
 */

public class XMLFactory {

    private static Parser domParser;
    private static Serializer domSerializer;

    private static Parser saxParser;
    private static Serializer saxSerializer;

    private static Parser pullParser;
    private static Serializer pullSerializer;

    public static Parser getDomParser(){
        if(domParser == null){
            synchronized (XMLFactory.class){
                if(domParser == null){
                    domParser = new DomParser();
                }
            }
        }
        return domParser;
    }

    public static Parser getSaxParser(){
        if(saxParser == null){
            synchronized (XMLFactory.class){
                if(saxParser == null){
                    saxParser = new SaxParser();
                }
            }
        }
        return saxParser;
    }

    public static Parser getPullParser(){
        if(pullParser == null){
            synchronized (XMLFactory.class){
                if(pullParser == null){
                    pullParser = new PullParser();
                }
            }
        }
        return pullParser;
    }

    public static Serializer getDomSerializer(){
        if(domSerializer == null){
            synchronized (XMLFactory.class){
                if(domSerializer == null){
                    domSerializer = new DomSerializer();
                }
            }
        }
        return domSerializer;
    }

    public static Serializer getSaxSerializer(){
        if(saxSerializer == null){
            synchronized (XMLFactory.class){
                if(saxSerializer == null){
                    saxSerializer = new SaxSerializer();
                }
            }
        }
        return saxSerializer;
    }

    public static Serializer getPullSerializer(){
        if(pullSerializer == null){
            synchronized (XMLFactory.class){
                if(pullSerializer == null){
                    pullSerializer = new PullSerializer();
                }
            }
        }
        return pullSerializer;
    }

}
